package day61_23;

/**
 * @ClassName ListNode
 * @Description TODO
 * @Author clockTown
 * @Date 2021/7/10 21:36
 * @Version 1.0
 */
public class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    ListNode(int[] array) {
        ListNode head = new ListNode();
        ListNode cur = head;
        for (int i = 0; i < array.length; i++) {
            cur.next = new ListNode(array[i]);
            cur = cur.next;
        }
        this.next = head.next;
    }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        ListNode temp = next;
        while (temp != null) {
            res.append(temp.val + "->");
            temp = temp.next;
        }
        res.append("NULL");

        return res.toString();
    }
}
